package com.yantong.service.impl;

import com.yantong.exception.BDException;
import com.yantong.utils.PageUtils;
import com.yantong.pojo.Member;
import com.yantong.pojo.MemberUseragent;
import com.yantong.mapper.MemberMapper;
import com.yantong.mapper.MemberUseragentMapper;
import com.yantong.service.MemberUseragentService;
import com.yantong.utils.ValidateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberUseragentServiceImpl implements MemberUseragentService {
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private MemberUseragentMapper memberUseragentMapper;

//    @Override
//    public MemberUseragent creatUseragentByMid(Long id) {
//        if (id == null) {
//            return null;
//        }
//        Member member = memberMapper.selectByPrimaryKey(id);
//        if (member == null) {
//            return null;
//        }
//        //同一个人只能有一个代理身份
//        if (member.getIsUseragent()==1){
//            return null;
//        }
//        MemberUseragent memberUseragent =new MemberUseragent();
//
//        memberUseragent.setMemberId(id);
////        if (ValidateUtil.isNotEmptyObjectOrString(member.getNickname())){
////            memberUseragent.setNickname(member.getNickname());
////        }
//        if (ValidateUtil.isNotEmptyObjectOrString(member.getRealname())){
//            memberUseragent.setRealname(member.getRealname());
//        }
//        if (ValidateUtil.isNotEmptyObjectOrString(member.getMobile())){
//            memberUseragent.setMobile(member.getMobile());
//        }
//        if (ValidateUtil.isNotEmptyObjectOrString(member.getCentreId())){
//            memberUseragent.setCentreId(member.getCentreId());
//        }
//        memberUseragentMapper.insertSelective(memberUseragent);
//        member.setIsUseragent(1);
//        memberMapper.updateByPrimaryKeySelective(member);
//        return memberUseragentMapper.selectByMid(id);
//    }


    @Override
    public List<MemberUseragent> memberUseragentList() {
        return memberUseragentMapper.memberUserAgentList();
    }

    @Override
    public MemberUseragent selectByMid(Long mid) {
        return memberUseragentMapper.selectByMid(mid);
    }

    @Override
    public MemberUseragent selectByPrimaryKey(Long useragentId) {
        return memberUseragentMapper.selectByPrimaryKey(useragentId);
    }

    @Override
    public int saveMemberUseragent(MemberUseragent memberUseragent) {
        if (memberUseragent == null) {
            return 0;
        }
        MemberUseragent memberUseragentOld = memberUseragentMapper.selectByPrimaryKey(memberUseragent.getUseragentId());
        if(memberUseragentOld != null){
            return 0;
        }else{
            return memberUseragentMapper.insertSelective(memberUseragent);
        }
    }

    @Override
    public PageUtils<MemberUseragent> listMemberUseragent(MemberUseragent memberUseragent, int offset, int limit) {
        return null;
    }

    @Override
    public int updateMemberUseragent(MemberUseragent memberUseragent) {
        return 0;
    }

    @Override
    public int removeMemberUseragent(Long id) {
        return 0;
    }

    @Override
    public MemberUseragent getMemberUseragentById(Long id) {
        return null;
    }
}
